import React from "react";
import { BrowserRouter, Navigate, Route, Routes } from "react-router-dom";
import { Spin } from "antd";
import routerConfig from "./routerConfig";

const renderRouter = (routerConfig) => {
  return routerConfig.map((item) => {
    const { path, children } = item;

    return (
      <Route key={path} path={path} element={<item.component />}>
        {!!children &&
          children.map((i) => {
            return (
              <Route key={i.path} path={i.path} element={<i.component />} />
            );
          })}
      </Route>
    );
  });
};
const Routers = () => {
  return (
    <BrowserRouter>
      <React.Suspense fallback={<Spin tip={"加载中"} />}>
        <Routes>{renderRouter(routerConfig)}</Routes>
      </React.Suspense>
    </BrowserRouter>
  );
};

export default React.memo(Routers);
